function htmlDecode(input){
	  var e = document.createElement('div');
	  e.innerHTML = input;
	  return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
}

function visualizarPDF(){
	var url = this.url +"?eventoId=" + this.eventoId;
	var w = window;
	salvar(null,null,false).then( function(){w.open(url,"_blank",null,true);} );	
}

function salvar(event,upload,displayMessage){
					
					
					if(!dijit.byId("formCadastrarEvento").validate()){
						
						if(upload){
							
							dijit.byId("divAdicionarArtefato").hide();
						}
						return false;
					}
					var evento = {};
					
					//Falta pegar participantes..
					
					evento.id = dojo.attr(dojo.byId("txtIdEvento"),'value');
					evento.custo = dijit.byId("txtCusto").get("value");
					if(isNaN(evento.custo)){
						evento.custo = 0;
					}
					evento.descricao = dojo.attr(dojo.byId("txtDescricao"),'value');
					evento.dtFim = dojo.date.locale.format(dijit.byId("txtDataFim").value, {datePattern: "yyyy-MM-dd", selector: "date"}); //Formatar
					evento.dtInicio = dojo.date.locale.format(dijit.byId("txtDataInicio").value, {datePattern: "yyyy-MM-dd", selector: "date"}); //Formatar
					evento.horaFim = dojo.date.locale.format(dijit.byId("txtHoraFim").get("value"),{selector:"date", datePattern:"hh:mm" } );//Formatar 
					evento.horaInicio = dojo.date.locale.format(dijit.byId("txtHoraInicio").get("value"),{selector:"date", datePattern:"hh:mm" } );//Formatar 
					evento.idNegociacao = dojo.attr(dojo.byId("txtIdNegociacao"),'value');
					evento.local = dojo.attr(dojo.byId("txtLocal"),'value');
					evento.memoria = CKEDITOR.instances['txtMemoria'].getData();//dojo.attr(dojo.byId("txtMemoria"),'value');
					
					console.log(evento.memoria);
					
					
					evento.participantes = control.getParticipantes();
					evento.tipoEvento = 1; //HardCoded
					//evento.tipoEventoNome = dojo.attr(dojo.byId("txtTipoEventoNome"),'value');
					evento.titulo = dojo.attr(dojo.byId("txtTitulo"),'value');	
					
					var param = JSON.stringify(evento);
					
					var caminho = "/reuniao/interno/evento?action=";
					
					//Algum check para dar update ou inserir.
					if( evento.id > 0){ 
						
						caminho += "update";
						
					}
					else{
						caminho += "insert";

					}
					
					var synch;
					
					
					//Controle de sincronismo
					if(upload){
						
						
						synch = true;
						
					}else{
						
						synch = false;
					}
					
					
					
					var deferred = dojo.xhrPost({
						
							url: caminho,
							handleAs: "text",
							sync : synch,
							content: { "json":param},
							contentType: "application/x-www-form-urlencoded; charset=utf-8",
							load: function(data){
							
								
								valor = parseInt(data);
								//alert("Evento salvo com sucesso!");
								
								if(valor > 0){
									dojo.attr(dojo.byId("txtIdEvento"),"value",valor);
									control.idEvento = valor;
									
									if(upload){
										
										//Do nothing.
										
									}else{
										if(displayMessage!=false){
											dijit.byId("divAlertOk").show();
										}
									}
								}
							
							},
							error: function(){

								dijit.byId("divAlertErro").show();
							}	
						});
					
					return deferred;
					
				}

function uploadFile(id){
	
	var unique_id = control.getUniqueId("loading_row");
	var descricao = dijit.byId("descricaoArtefato").get("value");	
	var tipoArtefato = dijit.byId("tipoArtefato").get("value");
	
	uploader.setParams({
		"idEvento": control.idEvento, 
	  	 "descricaoArtefato": descricao,
	  	 "tipoArtefato":7, //HARD_CODED
	  	 "domNodeId":unique_id
  	
	});
	
	var new_div = dojo.create("div");
	  dojo.attr(new_div,{
		  
		  "id":"loading_row_"+id,
		  "style":"height:30px;"  
	  });
	dojo.place(new_div,dojo.byId("divListaArtefatos"));
	if(dojo.isIE){
		
			dojo.attr(new_div,{
				
				"class":"loading row"
			});		  

	}else{
		
		new dijit.ProgressBar({
		
			"class":"row"
		},new_div);
		
	}
	
}

function downloadArtefato(index){
	
	
	var downloadPdfIframeName = "downloadIframe"; 
	var iframe = dojo.io.iframe.create(downloadPdfIframeName);
	dojo.io.iframe.setSrc(iframe, "/reuniao/interno/evento/artefato.download?idArtefato="+index, true);
	
}

function createNewLineForm(name,id,label,required){
	
	var div_linha = dojo.doc.createElement("div");
	var div_label = dojo.doc.createElement("div");
	var div_widget = dojo.doc.createElement("div");
	var div_input = dojo.doc.createElement("div");
	
	dojo.attr(div_linha,{
		"class":"form_divLinha"
	});
	
	dojo.attr(div_label,{
		"class":"form_divLabel"
	});
	
	dojo.attr(div_widget,{
		"class":"widget"
	});
	
	div_widget.appendChild( dojo.doc.createTextNode( label ) );
	div_label.appendChild(div_widget);
	
	div_linha.appendChild(div_label);
	div_linha.appendChild(div_input);
	
	var dj_input = new dijit.form.ValidationTextBox({
		"required":required,
		"name":name,
		"id":id
	},div_input);
	
	return div_linha;		    	
}


 